package com.qianfeng.zhangwei.day30_bdmap.base;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMapOptions;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.model.LatLng;
import com.qianfeng.zhangwei.day30_bdmap.R;

public class BaseMapActivity extends AppCompatActivity {
    private MapView mapView;
    private BaiduMap baiduMap;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        newView();
        setContentView(R.layout.activity_base_map);
        initView();
    }

    private void newView() {
        BaiduMapOptions options = new BaiduMapOptions();
        options.compassEnabled(true);
        MapStatus.Builder builder = new MapStatus.Builder().target(new LatLng(39.963175, 116.400244)).zoom(18);
        options.mapType(BaiduMap.MAP_TYPE_NORMAL);
        options.mapStatus(builder.build());
        options.scaleControlEnabled(true);
        options.zoomControlsEnabled(false);
        options.zoomGesturesEnabled(true);
        mapView = new MapView(this, options);
    }


    private void initView() {
        mapView = (MapView) this.findViewById(R.id.mapView);
        baiduMap = mapView.getMap();

        /**
         * 设置地图显示的类型
         *
         * BaiduMap.MAP_TYPE_SATELLITE 卫星图
         * BaiduMap.MAP_TYPE_NORMAL 2D平面图
         */

        baiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
        /**
         * 启用交通实况
         */
        baiduMap.setTrafficEnabled(true);
        /**
         * 设置显示热力图
         */
        baiduMap.setBaiduHeatMapEnabled(true);
        baiduMap.setMaxAndMinZoomLevel(3, 20);
        LatLng latLng = new LatLng(39.963175, 116.400244);
        MapStatusUpdate update = MapStatusUpdateFactory.newLatLngZoom(latLng, 18f);
        baiduMap.setMapStatus(update);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }
}
